package com.example.leetdemo.plan1;

public class Sword013 {

    static class NumMatrix {

        int[][] t;
        public NumMatrix(int[][] matrix) {
            t = new int[matrix.length][matrix[0].length + 1];
            for (int i = 0; i < matrix.length; i++) {
                for (int j = 1; j <= matrix[i].length; j++) {
                    t[i][j] = matrix[i][j] + t[i][j - 1];
                }
            }
        }

        public int sumRegion(int row1, int col1, int row2, int col2) {
            int sum = 0;
            for (int i = row1; i <= row2; i++) {
                sum += t[i][col2 + 1] - t[i][col1];
            }
            return sum;
        }
    }

    public static void main(String[] args) {
        NumMatrix numMatrix = new NumMatrix(new int[][] {{-4,-5}});
        System.err.println(numMatrix.sumRegion(0,0,0,0));
    }
}
